FROM node:18-alpine

# Set working directory
WORKDIR /app

# Copy package files
COPY package*.json ./

# Install dependencies
RUN npm ci --only=production

# Copy source and built files
COPY dist/ ./dist/
COPY src/ ./src/
COPY tsconfig.json ./

# Set executable permissions
RUN chmod +x dist/index.js

# Create non-root user
RUN addgroup -g 1001 -S mcp && \
    adduser -S mcp -u 1001 -G mcp

USER mcp

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
  CMD node dist/index.js status || exit 1

# Expose port
EXPOSE 3000

# Default entrypoint
ENTRYPOINT ["node", "dist/index.js"]
CMD ["start"]